#{extends 'main.html' /}
#{set title:'Teachers' /}

<script>
    function submitF() {
        $("#form").submit();
    }
    
    function submitU() {
    	$("#su_id").val(''+($("#s_id").val()));
    	$("#updateform").submit();
    }
</script>

<h1> Update Teacher </h1>

<form id ="form" action="@{Application.displayTeachers()}" method="POST">
    Select a teacher <select size="1" name="id" id = "s_id" onchange="submitF()"> 
                <option value="">--</option>
            #{list items:teachers, as:'su'}
                #{if su.id == id}
                <option selected="selected" value="${su.id}">${su.name}</option>
                #{/if}
                #{else}
                 <option value="${su.id}">${su.name}</option>
                #{/else}
            #{/list}
           </select> 

</form>
<br>
#{if id!= null}

<form id ="updateform" action="@{Application.updateTeacher()}" method="POST">
    <input type="hidden" id = "su_id" name = "id">
    <script>
    $("#su_id").val(''+($("#s_id").val()));
    </script>
    <table border="0">
    <tbody>
    <tr><td>Name</td>
    <td> <input type="text" name="name" value="${t.name}" required ="required"/>*
    </td></tr>
    <tr><td>Home Address </td><td><input type="text" name="address" value="${t.address}" /></td></tr>
    <tr><td>Home Phone </td><td> <input type="text" name="homePhone" value="${t.homePhone}" required ="required"/>* </td></tr>
    <tr><td>Mobile #1 </td><td> <input type="text" name="mobilePhone1" value = "${t.mobilePhone1}" required ="required"/>* </td></tr>
    <tr><td>Mobile #2 </td><td><input type="text" name="mobilePhone2" value="${t.mobilePhone2}" /> </td></tr>
    <tr><td>Email #1 </td><td><input type="text" name="email1" value ="${t.email1}" required ="required"/>* </td></tr>
    <tr><td>Email #2 </td><td><input type="text" name="email2" value ="${t.email2}" /> </td></tr>
    
    </tbody>
    </table>
    <br>
    <input type="submit" value="Update"/>
    
</form>
<br>
<!--  <button onclick="submitU()">Update</button>-->

#{/if}